Well-named functions can allow the users of your code to understand at a glance what to expect from the function - even before reading the
documentation. Toward that end, methods returning a boolean should have names that start with "is" or "has" rather than with "get".
Noncompliant code example
public boolean getFoo() { // Noncompliant
// ...
}
public boolean getBar(Bar c) { // Noncompliant
// ...
}
public boolean testForBar(Bar c) { // Compliant - The method does not start by 'get'.
// ...
}
Compliant solution
public boolean isFoo() {
// ...
}
public boolean hasBar(Bar c) {
// ...
}
public boolean testForBar(Bar c) {
// ...
}
Exceptions
Overriding methods are excluded.
@Override
public boolean getFoo(){
// ...
}